<?php

namespace app\admin\model\operation;

use app\common\model\TimeModel;

/**
 * @property int $id 文档id 
 * @property int $to_user_id 指定接收人ID 
 * @property string $title 消息标题 
 * @property string $content 消息内容 
 * @property string $order_sn 订单号 
 * @property string $custom 自定义透传 
 * @property int $type 消息类型 1:单推,2:多推,3:全部推
 * @property string $pop_title 弹窗标题 
 * @property string $pop_content 弹窗内容 
 * @property string $download 下载地址 
 * @property int $msg_type 消息分类 10:系统消息,20:订单消息
 * @property int $template_type 消息类型 ,4:通知弹框) 1:通知透,2:打开链接功能,3:透传功能ios
 * @property int $is_all 全体消息 0:否,1:是
 * @property int $create_time 创建时间 
 */
class OperationSystemMessage extends TimeModel
{

    protected $name = "operation_system_message";

    protected $deleteTime = false;

    
    public const SELECT_LIST_TYPE = ['1'=>'单推','2'=>'多推','3'=>'全部推',];

    public const SELECT_LIST_MSG_TYPE = ['10'=>'系统消息','20'=>'订单消息',];

    public const SELECT_LIST_TEMPLATE_TYPE = ['1'=>'通知透','2'=>'打开链接功能','3'=>'透传功能ios',];

    public const SELECT_LIST_IS_ALL = ['0'=>'否','1'=>'是',];

    public function user()
    {
        return $this->belongsTo('\app\admin\model\user\User', 'to_user_id', 'id');
    }

    public function order()
    {
        return $this->belongsTo('\app\common\model\Order', 'order_id', 'id');
    }

    /**
     * 增加订单消息记录
     * @author mitu
     * @date   2023-12-11
     * @param  [type]     $order         [description]
     * @param  string     $title         [description]
     * @param  string     $content       [description]
     * @param  string     $thumb         [description]
     * @param  string     $custom        [description]
     * @param  integer    $msg_type      [description]
     * @param  integer    $template_type [description]
     * @param  integer    $is_all        [description]
     */
    public static function add($order, $title = '', $content = '', $thumb = '', $custom = '', $msg_type = 20, $template_type = 1, $is_all = 0)
    {
        return self::create([
            'to_user_id' => $order['user_id'] ?? 0,
            'title' => $title,
            'content' => $content,
            'order_id' => $order['id'],
            'custom' => $custom,
            'thumb' => $thumb,
            'type' => $is_all ? 3 : 1,//1:单推,2:多推,3:全部推
            'msg_type' => $msg_type,
            'template_type' => $template_type,//1:通知,2:打开链接功能,3:透传功能(ios),4:通知弹框
            'is_all' => $is_all,
        ]);
    }


}